package parser;

import java.util.ArrayList;

public class SyntaxNode
{
    private ArrayList<SyntaxNode> children = new ArrayList<SyntaxNode>();
    private SyntaxNodeType type;
    private Object data;

    public SyntaxNode(SyntaxNodeType type)
    {
        this.type = type;
    }

    public SyntaxNode(SyntaxNodeType type, Object data)
    {
        this.type = type;
        this.data = data;
    }

    public void AddChild(SyntaxNode node)
    {
        children.add(node);
    }

    public int GetChildrenCount()
    {
        return children.size();
    }

    public SyntaxNode GetChild(int index)
    {
        return (index >= 0 && index < children.size())
                ? children.get(index)
                : null;
    }

    public boolean HasChildren()
    {
        return children.size() > 0;
    }

    public String toString()
    {
        return (data != null)
                ? type + " (data = " + data + ")"
                : type.toString();
    }
}
